package com.share.beta.config.proxy;

import org.mitre.dsmiley.httpproxy.ProxyServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * java实现反向代理,类似于nginx
 */
@Configuration
public class NginxProxy {
    private String servletUrlDownload = "/uploading/*";

    private String targetUrlDownload = "http://192.168.0.142/file";

    @Bean
    @SuppressWarnings(value = {"unchecked", "rawtypes"})
    public ServletRegistrationBean proxyServletRegistrationDownload() {
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new ProxyServlet(), servletUrlDownload);
        registrationBean.addInitParameter("targetUri", targetUrlDownload);//代理的目标地址
        registrationBean.addInitParameter("log", "true");//是否打日志
        return registrationBean;
    }
}
